using System;
using Input;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour, InputSystem_Player.IGameActions
{
    private InputSystem_Player input;
    private PlayerStateMachine stateMachine;
    
    private Vector2 MoveActionValue;
    
    public Vector3 forward { get; private set; }
    
    private void Awake()
    {
        input = new InputSystem_Player();
        
    }

    private void Start()
    {
        GameMode.instance.SetController(this);
    }

    private void OnEnable()
    {
        input.Game.SetCallbacks(this);
        input.Game.Enable();
    }


    public Vector2 GetMoveValue() => MoveActionValue;

    public bool wasJump() => input.Game.Jump.WasPressedThisFrame();
    public bool wasDash() => input.Game.Dash.WasPressedThisFrame();

    public void Flip()
    {
        var x = -forward.x;
        transform.localScale = new Vector3(x, 1, 1);
        forward = new Vector3(x, 0, 0);
    }

    public void OnMove(InputAction.CallbackContext context)
    {
        MoveActionValue = context.ReadValue<Vector2>();
        if (MoveActionValue.x > 0)
        {
            // transform.rotation = Quaternion.Euler(0,0,0);
            transform.localScale = new Vector3(1, 1, 1);
            forward = new Vector3(1, 0, 0);
        }
        else if (MoveActionValue.x < 0)
        {
            // transform.rotation = Quaternion.Euler(0,180,0);
            transform.localScale = new Vector3(-1, 1, 1);
            forward = new Vector3(-1, 0, 0);
        }
    }
    
    

    public void OnJump(InputAction.CallbackContext context)
    {
        
    }

    public void OnDash(InputAction.CallbackContext context)
    {
        
    }

    public void OnAttack(InputAction.CallbackContext context)
    {
        
    }
}
